from env import ENDPOINT, ACCESS_ID, ACCESS_KEY, USERNAME, PASSWORD, DEVICE_ID

import sys
sys.path.append("..")
from tuya_iot import TuyaOpenAPI, tuya_logger

# Initialization of tuya openapi
openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.login(USERNAME, PASSWORD)

# # Uncomment the following lines to see logs.
import logging

tuya_logger.setLevel(logging.DEBUG)

flag = True
while True:
    input('Hit Enter to toggle light switch.')
    commands = {'commands': [{'code': 'switch_1', 'value': flag}]}
    openapi.post('/v1.0/iot-03/devices/{}/commands'.format(DEVICE_ID), commands)

